package com.zhiyou100.blog.aciton.message;

import com.zhiyou100.blog.entity.Message;
import com.zhiyou100.blog.service.MessageService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * @author shkstart
 * @create 2021-10-25 10:10
 * 添加 留言
 */
@WebServlet("/message/addition")
public class MessageAdditionServlet extends HttpServlet {
    private MessageService service = new MessageService();

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String mcontent = request.getParameter("mcontent");
        String uid = request.getParameter("uid");
        String tid = request.getParameter("tid");
        Message message = new Message(mcontent, new Date(), Integer.parseInt(uid), Integer.parseInt(tid));
        System.out.println("保存数据 message = " + message);
        service.messageAddition(message);

        //转发到 展示 文章的servlet重新查询一边
        request.getRequestDispatcher("/title/showMessage?tid=" + message.getTid()).forward(request, response);

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
